package com.neuedu.action.web;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.neuedu.model.Food;
import com.neuedu.model.FoodMake;
import com.neuedu.model.FoodType;
import com.neuedu.model.Notice;
import com.neuedu.model.UserMessage;
import com.neuedu.service.FoodMakeService;
import com.neuedu.service.FoodService;
import com.neuedu.service.FoodTypeService;
import com.neuedu.service.NoticeService;

@Controller
@RequestMapping(value = "/MenuWeb")
public class MenuWebAction {
	@Autowired
	private FoodService foodService;

	@Autowired
	private FoodTypeService foodTypeService;

	@Autowired
	private FoodMakeService foodMakeService;

	/*
	 * // 查询所有菜谱
	 * 
	 * @RequestMapping(value = "/findAllMenu") public String
	 * findAllMeun(HttpServletRequest request, HttpServletResponse response) throws
	 * Exception {
	 * 
	 * // 所有菜谱 List<Food> f = foodService.findAllMenu();
	 * request.setAttribute("foodlist", f);
	 * 
	 * return "menu";
	 * 
	 * }
	 */

	// 菜谱详情页
	@RequestMapping(value = "/findFoodById")
	public String findFoodById(Food food, HttpServletRequest request, HttpServletResponse response) throws Exception {

		// 所有菜谱
		Food f = foodService.findFoodById(food);
		request.setAttribute("fooddetail", f);

		// 美食做法
		List<FoodMake> fm = foodMakeService.findMake();
		request.setAttribute("foodmake", fm);

		// 美食类型
		List<FoodType> ftp = foodTypeService.findType();
		request.setAttribute("foodtype", ftp);

		return "menudetail";

	}

	// 根据做法查询所有菜谱
	@RequestMapping(value = "/findFoodByMakeNo")
	public String findFoodByMakeNo(Food food, HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		// 所有菜谱
		List<Food> m = foodService.findFoodByMakeNo(food);
		request.setAttribute("foodByMakeNolist", m);

		// 美食做法
		List<FoodMake> fm = foodMakeService.findMake();
		request.setAttribute("foodmake", fm);

		// 美食类型
		List<FoodType> ftp = foodTypeService.findType();
		request.setAttribute("foodtype", ftp);

		return "cook";

	}

	// 根据类型查询菜谱
	@RequestMapping(value = "/findFoodByTypeNo")
	public String findFoodByTypeNo(Food food, HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		// 根据类型查询显示菜谱
		List<Food> ft = foodService.findFoodByTypeNo(food);
		request.setAttribute("foodByTypelist", ft);

		// 美食类型
		List<FoodType> ftp = foodTypeService.findType();
		request.setAttribute("foodtype", ftp);

		// 美食做法
		List<FoodMake> fm = foodMakeService.findMake();
		request.setAttribute("foodmake", fm);

		return "menu";
	}

	//  前台搜索框根据名称搜索
	@RequestMapping(value = "/findFoodByName")
	public String findFoodByName(Food food, HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		// 根据搜索框根据名称搜索
		Food f = foodService.findFoodByName(food);
		request.setAttribute("foodname", f);

		// 美食类型
		List<FoodType> ftp = foodTypeService.findType();
		request.setAttribute("foodtype", ftp);

		// 美食做法
		List<FoodMake> fm = foodMakeService.findMake();
		request.setAttribute("foodmake", fm);

		
		return "menudetail";
	}

}
